package org.qf.service.impl;

import org.qf.dao.SmbmsUserDao;
import org.qf.dao.impl.SmbmsUserDaoImpl;
import org.qf.pojo.SmbmsUser;
import org.qf.service.SmbmsUserService;

import java.util.List;

/**
 * @author young
 * @create 2021-01-11-11:46
 * @description
 */
public class SmbmsUserServiceImpl implements SmbmsUserService {

    //dao层
    private SmbmsUserDao smbmsUserDao=new SmbmsUserDaoImpl();


    //登录功能
    @Override
    public SmbmsUser login(String userCode, String password) throws Exception {

        SmbmsUser smbmsUser = smbmsUserDao.queryUserByUserCode(userCode);

        if(null !=smbmsUser){
            //通过密码进行判断
            System.out.println(smbmsUser.getUserCode());
            if(!password.equals(smbmsUser.getUserPassword())){
                smbmsUser=null;
            }
        }
        return smbmsUser;
    }

    @Override
    public int upadatePw(String oldPassword, String newPassword) throws Exception {
        return smbmsUserDao.upDatepw(oldPassword,newPassword);
    }

    @Override
    public List<SmbmsUser> queryList(String username, int userRole, int currentPageNo, int pageSize) throws Exception {
        return smbmsUserDao.queryUserByUserName(username, userRole, currentPageNo, pageSize);
    }

    @Override
    public int getSmbmsUserCount(String username, int userRole) throws Exception {
        return smbmsUserDao.getSmbmsUserCount(username, userRole);
    }
    //通过id查询所有信息
    @Override
    public SmbmsUser queryUserById(Long id) throws Exception {
        return smbmsUserDao.queryUserById(id);
    }

    @Override
    public int updateUser(SmbmsUser smbmsUser) throws Exception {
        return smbmsUserDao.updateUser(smbmsUser);
    }

    @Override
    public int addUser(SmbmsUser smbmsUser) throws Exception {
        return smbmsUserDao.addUser(smbmsUser);
    }

    @Override
    public int deleteUser(Long id) throws Exception {
        return smbmsUserDao.deleteUser(id);
    }


}
